package com.ewanghuiju.app.ui.pintuan.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.model.bean.response.PintuanOrderListResponBean;
import com.makeramen.roundedimageview.RoundedImageView;
import com.stx.xhb.androidx.OnDoubleClickListener;

/**
 * @author sj  qq:751943509
 * @class 订单列表 adapter
 * @time 2020/2/20
 */
public class PintuanOrderListAdapter extends BaseQuickAdapter<PintuanOrderListResponBean, BaseViewHolder> {
    private int mType;

    public PintuanOrderListAdapter(int layoutResId, int type) {
        super(layoutResId);
        this.mType = type;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    protected void convert(BaseViewHolder helper, PintuanOrderListResponBean item) {
        ImageView riv_head = helper.getView(R.id.iv_head);
        riv_head.setBackgroundResource(R.mipmap.ic_order_logo);
//       ImageLoader.load(mContext,item.getHead(),riv_head);
        RoundedImageView iv_shop_img = helper.getView(R.id.iv_shop_img);
        ImageLoader.load(mContext, item.getImage(), iv_shop_img);

        helper.setText(R.id.tv_title, TextUtils.isEmpty(item.getGoods_name()) ? "" : item.getGoods_name());
        helper.setText(R.id.tv_shopname, TextUtils.isEmpty(item.getCreate_time()) ? "" : item.getCreate_time());
        helper.setText(R.id.tv_price, TextUtils.isEmpty(item.getPrice()) ? "" : item.getPrice());
        TextView mTvPintuanStatus = helper.getView(R.id.tv_pintuan_status);
        if (item.getGroup_status() == 1) {
            mTvPintuanStatus.setText("正在拼团");
        } else if (item.getGroup_status() == 2) {
            mTvPintuanStatus.setText("拼团成功");
        } else if (item.getGroup_status() == 3) {
            mTvPintuanStatus.setText("拼团失败");
        }

        TextView mTvfukuan = helper.getView(R.id.tv_fukuan);
        //客服
        TextView tvKf = helper.getView(R.id.tv_kf);
        //查看物流
        TextView tvLlookwl = helper.getView(R.id.tv_look_wl);
        //确认收货
        TextView tvSuresh = helper.getView(R.id.tv_sure_sh);
        //邀请好友  --->拼团详情
        TextView tvInviteFriend = helper.getView(R.id.tv_invite_friend);
        //查看钱包
        TextView tvLookWallet = helper.getView(R.id.tv_look_wallet);
        //立即评价
        TextView tvLjpj = helper.getView(R.id.tv_ljpj);

        tvSuresh.setVisibility(View.GONE);
        tvLlookwl.setVisibility(View.GONE);
        tvLjpj.setVisibility(View.GONE);
        tvLookWallet.setVisibility(View.GONE);
        tvInviteFriend.setVisibility(View.GONE);
        tvKf.setVisibility(View.VISIBLE);
        if (item.getStatus() == 1) {
            //拼团成功
            mTvfukuan.setText("已付款");
            tvInviteFriend.setVisibility(View.VISIBLE);
        } else if (item.getStatus() == 101) {
            //拼团成功 -- 待发货
            mTvfukuan.setText("待发货");
        } else if (item.getStatus() == 102) {
            //拼团成功 ---  待收货
            mTvfukuan.setText("待收货");
            tvSuresh.setVisibility(View.VISIBLE);
            tvLlookwl.setVisibility(View.VISIBLE);
        } else if (item.getStatus() == 103) {
            //拼团成功 --- 待评价
            mTvfukuan.setText("待评价");
            tvLjpj.setVisibility(View.VISIBLE);
        } else if (item.getStatus() == 104) {
            //拼团成功 --- 获得收益
            mTvfukuan.setText("获得收益");
            tvLookWallet.setVisibility(View.VISIBLE);
        } else if (item.getStatus() == 105) {
            //拼团成功 --- 已完成
            mTvfukuan.setText("已完成");
        } else if (item.getStatus() == 201) {
            //拼团成功 --- 正在退款
            mTvfukuan.setText("正在退款");
        } else if (item.getStatus() == 202) {
            //拼团成功 --- 已退款
            mTvfukuan.setText("已退款");
            tvLookWallet.setVisibility(View.VISIBLE);
        }
        helper.getView(R.id.tv_kf).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //客服
                if (mOnButtonClick != null)
                    mOnButtonClick.onKefu();
            }
        });

        helper.getView(R.id.tv_look_wl).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //查看物流
                if (mOnButtonClick != null)
                    mOnButtonClick.onLookwl(item.getCourier_link());
            }
        });

        helper.getView(R.id.tv_sure_sh).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //确认收货
                if (mOnButtonClick != null)
                    mOnButtonClick.onSuresh(item.getId());
            }
        });

        helper.getView(R.id.tv_invite_friend).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //邀请好友  ---拼团详情
                if (mOnButtonClick != null)
                    mOnButtonClick.onInviteFriend(item.getGoods_id() + "", item.getGroup_id());
            }
        });
        helper.getView(R.id.tv_look_wallet).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //查看钱包
                if (mOnButtonClick != null)
                    mOnButtonClick.onLookWallet();
            }
        });
        helper.getView(R.id.tv_ljpj).setOnClickListener(new OnDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                //立即评价
                if (mOnButtonClick != null)
                    mOnButtonClick.onLjpj(item);
            }
        });

    }

    private OnButtonClick mOnButtonClick;

    public void setButtonClick(OnButtonClick mOnButtonClick) {
        this.mOnButtonClick = mOnButtonClick;
    }

    public interface OnButtonClick {
        //客服
        void onKefu();

        //查看物流
        void onLookwl(String url);

        //确认收货
        void onSuresh(int orderId);

        //邀请好友
        void onInviteFriend(String goodsid, String groupid);

        //查看钱包
        void onLookWallet();

        //立即评价
        void onLjpj(PintuanOrderListResponBean bean);
    }
}
